from tool_interval import *

s1 = Sequence([(0,10)])
s2 = Sequence([(5,15)])

print 'repr(s1) :: ', repr(s1)
print 'repr(s2) :: ', repr(s2)

print 's1 :: ', s1
print 's2 :: ',s2

s3 = s1 + s2
print 's3 = s1 + s2 :: ', s3
s3 += s1
print 's3 += s1 :: ', s3

s4 = s3.union()
print 's4 = s3.union() :: ', s4
s4_bis = s3 | s3
print 's4_bis = s3 | s3 :: ', s4_bis


s5 = Sequence([(20,22)])
print 's5 :: ', s5

s5 = s1 | s2
print 's5 = s1 | s2 :: ', s5
s5 |= s1
print 's5 |= s1 :: ', s5

s5 = s1 & s2
print 's5 = s1 & s2 :: ', s5
s5 &= s1
print 's5 &= s1 :: ', s5

s6 = s1 % s5
print 's6 = s1 % s5 :: ', s6


print
print '*'*30
print

u1 = Sequence([(0,4), (5,7), (3,6), (10,11)])
print 'u1::', u1
u1 = u1.union()
print 'u1.union()::', u1

u2 = Sequence([(1,1), (3,3), (5,5), (7,7), (9,9), (11,11), (13,13)])
print 'u2::', u2
u2 = u2.union()
print 'u2.union()::', u2


str1 = "If it is beautiful, it must be true."
str1_unicode = unicode(str1, 'utf-8')

ts = Tool_sequencing()

tags1 = ('[',']')
str1_seg = ts.segment_text_multitag(str1_unicode,[u1],[tags1])
print 'str1 segmented with u1 :: ', str1_seg
tags2 = ('{','}')
str1_seg = ts.segment_text_multitag(str1_unicode,[u2],[tags2])
print 'str1 segmented with u2 :: ', str1_seg

t = [tags1,tags2]
u = u1 + u2
layers = u.intersections()

for i, seq in layers.iteritems() :
  str_seg = ts.segment_text_multitag(str1_unicode,[Sequence(seq)],[t[i-1]])
  print 'layer %s :: '%(i), seq
  print 'str1 segmented in layer %s :: '%(i), str_seg

u = [u1, u2]
smart_seg = ts.segment_text_multitag(str1_unicode, u, t)
print 'smart-segmented str1 :: ', smart_seg

#u1 = [(1,3), (10,10), (15,16), (20,22), (23,25)]
#u2 = [(2,2), (9,11), (17,18), (19,21), (24,26)]

r = ts.filter_seq(u[0].list_intervals,u[1].list_intervals)
print 'u2 in u1 :: ', r
